/** 
 * Project Name:Food_Sysrem 
 * File Name:Delete_Info.java 
 * Package Name:priv.web.control 
 * Date:2018年5月31日下午3:35:49 
 * Copyright (c) 2018, Fkuennh All Rights Reserved. 
 * 
 */

package priv.web.control;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.web.util.ReviewJDBCUtil;

public class Delete_Info extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		   String sql = "delete from food_users where b_id=?";
		   try {
			int updateSal = ReviewJDBCUtil.updateSal(sql,req.getParameter("user_id"));
			if(updateSal>0){
				resp.getWriter().print(JSON.toJSONString(new Package(1, "Success to Delete", null)));
			}else {
				resp.getWriter().print(JSON.toJSONString(new Package(0, "Failure to Delete", null)));
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	
	
//	
//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
//			throws ServletException, IOException {
//		
//		   String sql = "delete from food_users where b_id=?";
//		int self = Delete(req);
//		resp.setContentType("application/json;charset=utf-8");
//		if (self > 0) {
//			resp.getWriter().print(
//					JSON.toJSONString(new Package(1, "OK", null)));
//		} else {
//			resp.getWriter().print(
//					JSON.toJSONString(new Package(0,
//							"Please Check if your ID is right", null)));
//		}
//
//	}
//
//	private int Delete(HttpServletRequest req) {
//		Connection conn =null;
//		try {
////			int i = Integer.valueOf(req.getParameter("user_id"));
//			int i = Integer.parseInt(req.getParameter("user_id"));
//
//			// 数据库地址
//			String JDBC = "jdbc:mysql://localhost:3306/food_project?useUnicode=true&characterEncoding=UTF8";
//
//			// 加载驱动
//			Class.forName("com.mysql.jdbc.Driver");
//
//			// 建立连接
//			conn = DriverManager.getConnection(JDBC, "root", "123");
//			// 要执行的SQl语句
//			String sql = "delete from food_users where b_id=?";
//
//			// 承载容器
//			// Statement 用于在已经建立数据库连接的基础上，向数据库发送要执行的SQL语句
//			PreparedStatement createStatement = conn.prepareStatement(sql);
//
//			createStatement.setInt(1, i);
//
//			// 上传SQL语句到数据库执行
//			return createStatement.executeUpdate();
//
//			
//		} catch (Exception e) {
//			e.printStackTrace();
//			// TODO: handle exception
//		}finally{
//			// 关闭通道
//			try {
//				if(conn!=null)conn.close();
//			} catch (SQLException e) {
//				e.printStackTrace();
//			}
//		}
//		return 0;
//	}
//
}
